package view.Bullet
{
	import starling.display.Image;
	import starling.display.Sprite;
	
	import utils.LevelConfigXmlUtils;
	/**用于提示下一个出现的子弹*/
	public class BulletForTipView extends Sprite
	{
        /**提示子弹用的背景*/
		private var bulletForTipBg:Image;
        /**提示子弹用的子弹图片*/
		private var _bulletForTipImg:Image;
        /**提示子弹用的子弹ID*/
		private var _bulletForTipId:uint;
        /**提示子弹用的子弹Name*/
		private var _bulletName:String;
        /**图片有所偏离，规整位置坐标*/
        private static const OFFSET_X:uint = 4;
        private static const OFFSET_Y:uint = 4;
		public function BulletForTipView(bulletId:uint):void
		{
			super();
			_bulletForTipId = bulletId;
			drawBg();
			drawBulletForTipImg();
		}
		
		private function drawBulletForTipImg():void
		{
			var list:XMLList = LevelConfigXmlUtils.getInstance().xml.bulletConfig.child("group").child("item");
			var i:uint;
            var len:uint = list.length();
			for(i=0;i < len;i++){
				if(list[i].@id == _bulletForTipId.toString()){
					bulletName = list[i].@name;   
					break;
				}
			}
			_bulletForTipImg = new Image(Assets.getAtlas().getTexture(bulletName));
			_bulletForTipImg.x = 4;
			_bulletForTipImg.y = 4;
			addChild(_bulletForTipImg);
		}
		
		private function drawBg():void{
			bulletForTipBg = new Image(Assets.getAtlas().getTexture("bulletForTip"));
			addChild(bulletForTipBg);
		}
		
		public function showNextBulletTip(bulletId:uint):void{
            if(contains(bulletForTipImg))
                removeChild(bulletForTipImg);
			bulletForTipImg.dispose();
			var list:XMLList = LevelConfigXmlUtils.getInstance().xml.bulletConfig.child("group").child("item");
			var i:uint;
            var len:uint = list.length();
			for(i=0;i < len;i++){
				if(list[i].@id == bulletId.toString()){
					bulletName = list[i].@name;   
					break;
				}
			}
			
			bulletForTipImg = new Image(Assets.getAtlas().getTexture(bulletName));
			bulletForTipImg.x = OFFSET_X;
			bulletForTipImg.y = OFFSET_Y;
			addChild(bulletForTipImg);
		}

/*-----------------------------getter and setter----------------------------*/
		public function get bulletForTipId():uint
		{
			return _bulletForTipId;
		}

		public function set bulletForTipId(value:uint):void
		{
			_bulletForTipId = value;
		}

		public function get bulletName():String
		{
			return _bulletName;
		}

		public function set bulletName(value:String):void
		{
			_bulletName = value + "1";
		}

		public function get bulletForTipImg():Image
		{
			return _bulletForTipImg;
		}

		public function set bulletForTipImg(value:Image):void
		{
			_bulletForTipImg = value;
		}

	}
}
